import tkinter as tk
import os
from appFunction import transfer
url = os.getcwd()
url1 = os.path.abspath(os.getcwd()+r'\icon\favicon128.ico')
url2 = os.path.abspath(os.getcwd()+r'\header.gif')
print(url2)
print(url1)
print(os.path.abspath(os.path.dirname(os.getcwd())))
print(r'E:\Python\app\header.gif')
window = tk.Tk()
window.iconbitmap(os.path.abspath(os.path.dirname(os.getcwd()))+r'\icon\favicon128.ico')
window.geometry('600x450')
window.minsize(600, 450)
window.maxsize(600, 450)
window.title('word页眉表格内容替换')

canvas= tk.Canvas(window,height=100,width=600)
image_file = tk.PhotoImage(file=r'E:\Python\app\header.gif')
image= canvas.create_image(0,0,anchor='nw',image=image_file)
canvas.pack()
fram = tk.Frame(window)
fram.pack()

fram1 = tk.Frame(fram)
fram1.pack(side='left', padx=10, pady=20)

label1 = tk.Label(fram1, text='文件夹路径：', font=('仿宋', 12), width=15, height=2)
label1.grid(row=0, column=0)
path = tk.StringVar()
path = tk.Entry(fram1, textvariable=path, takefocus=True, font=('仿宋', 12))
path.grid(row=0, column=1)

label1 = tk.Label(fram1, text='旧的内容：', font=('仿宋', 12), width=15, height=2)
label1.grid(row=1, column=0)
old_value = tk.StringVar()
old_value = tk.Entry(fram1, textvariable=old_value, font=('仿宋', 12))
old_value.grid(row=1, column=1)

label1 = tk.Label(fram1, text='新的内容:', font=('仿宋', 12), width=15, height=2)
label1.grid(row=2, column=0)
new_value = tk.StringVar()
new_value = tk.Entry(fram1, textvariable=new_value, font=('仿宋', 12))
new_value.grid(row=2, column=1)

def trans():
    pat= path.get()
    old = old_value.get()
    new = new_value.get()
    msg,msg3=transfer(pat, old, new)
    label2['text']=msg
    for i in msg3:
        i = i.rsplit('\\')[-1]
        text1.insert('end',i+'\n')
        print(i)

fram2 = tk.Frame(fram)
fram2.pack(side='right', padx=15)
btn1 = tk.Button(fram2, text='替  换', command=trans, font=('仿宋', 12),
                 width=10, height=2)
btn1.grid(row=0, column=0)

fram3 = tk.Frame(window)
fram3.pack(after=fram )

text1 = tk.Text(fram3, font=('仿宋', 12), width=70,height=6)
text1.pack()
label2 = tk.Label(fram3, text='.....', font=('仿宋', 12), width=300, height=2)
label2.pack()

window.mainloop()
